#!/usr/bin/env bash

start() {
	status
	if [ ! $? -eq 0 ]; then
		echo "process is already running.."
		return 1
	fi

    # 启动解析代码
    nohup python start_parse_task.py new_gsxt > /dev/null 2>&1 &

    echo "process start success..."
}

stop() {
    # 关闭详情页
    ps -ef | grep python | grep -v grep | grep start_parse_task | grep new_gsxt | awk '{print $2}' | xargs kill -9

	status
	[ $? -eq 0 ] && echo "process stop success..." && return 1

	echo "process stop fail..."
	return 0
}

restart() {
    stop
    sleep 1
    start
}

status() {

    pid=`ps -ef | grep python | grep -v grep | grep start_parse_task | grep new_gsxt | awk '{print $2}'`
    if [ -z "${pid}" ]; then
        return 0
    fi
    echo "start_parse_task ${pid}"

    return 1
}

case "$1" in
	start|stop|restart|status)
  		$1
		;;
	*)
		echo $"Usage: $0 {start|stop|status|restart}"
		exit 1
esac
